#pragma once
#include "Engine/AuxTypes.h"


inline D3DDECLTYPE DX9DeclType ( TVariableType a_Type )
{
    switch (a_Type)
    {
    case TFLOAT:
        return D3DDECLTYPE_FLOAT1;

    case TFLOAT2:
        return D3DDECLTYPE_FLOAT2;

    case TFLOAT3:
        return D3DDECLTYPE_FLOAT3;

    case TFLOAT4:
        return D3DDECLTYPE_FLOAT4;

    /* No uint/int support */
    case TUINT32:
        return D3DDECLTYPE_UNUSED;

    case TINT32:
        return D3DDECLTYPE_UNUSED;
    }

    return D3DDECLTYPE_UNUSED;
}

inline D3DDECLUSAGE DX9Semantic ( const std::string& a_sSemantic )
{    
    if (a_sSemantic == "POSITION")
    	return D3DDECLUSAGE_POSITION;

    if (a_sSemantic == "TEXCOORD")
        return D3DDECLUSAGE_TEXCOORD;

    if (a_sSemantic == "NORMAL")
        return D3DDECLUSAGE_NORMAL;

    if (a_sSemantic == "BINORMAL")
        return D3DDECLUSAGE_BINORMAL;

    if (a_sSemantic == "BLENDWEIGHT")
        return D3DDECLUSAGE_BLENDWEIGHT;

    if (a_sSemantic == "BLENDINDICES")
        return D3DDECLUSAGE_BLENDINDICES;

    /* some shit must happens */
    return D3DDECLUSAGE_POSITION;
}


inline D3DFORMAT DX9ImageFmt ( TImageFormat a_Type )
{
    switch (a_Type)
    {
    case TR8:
        return D3DFMT_L8;

    case TR8G8B8A8:
        return D3DFMT_A8B8G8R8;

    case TR32F:
        return D3DFMT_R32F;

    case TR32G32B32A32F:
        return D3DFMT_A32B32G32R32F;

    }
    return D3DFMT_UNKNOWN;
}

inline D3DPRIMITIVETYPE DX9PrimitiveType ( TPrimitiveType a_Type )
{
    switch (a_Type)
    {
    case TPOINTLIST:
        return D3DPT_POINTLIST;

    case TLINELIST:
    case TLINELIST_ADJ:
        return D3DPT_LINELIST;

    case TLINESTRIP:
    case TLINESTRIP_ADJ:
        return D3DPT_LINESTRIP;

    case TTRIANGLELIST:
    case TTRIANGLELIST_ADJ:
        return D3DPT_TRIANGLELIST;

    case TTRIANGLESTRIP:
    case TTRIANGLESTRIP_ADJ:
        return D3DPT_TRIANGLESTRIP;    
    }
    return D3DPT_FORCE_DWORD;
}

inline mUInt DX9VertexCountToPrimitiveCount( TPrimitiveType a_Type, mUInt a_uVertexCount )
{
    switch (a_Type)
    {
    case TPOINTLIST:
        return a_uVertexCount;

    case TLINELIST:
    case TLINELIST_ADJ:
        return a_uVertexCount / 2;

    case TLINESTRIP:
    case TLINESTRIP_ADJ:
        return a_uVertexCount - 1;

    case TTRIANGLELIST:
    case TTRIANGLELIST_ADJ:
        return a_uVertexCount / 3;

    case TTRIANGLESTRIP:
    case TTRIANGLESTRIP_ADJ:
        return a_uVertexCount - 2;    
    }
    return 0;
}